<?php require '../../sesionabierta.php'; ?>
<?php include '../../../conexionbd/conexion.php';?>
<!DOCTYPE html>
<html lang="en">
<?php require '../../cabecera.php';?>

  <body>

<?php include("../../modulos.php");?>
    <div class="container-fluid">
      <div class="row-fluid">
    <?php include ('../listamodulo.php'); ?>
        <div class="span10">
          <div class="hero-unit">
            <h4>Modificar Credenciales</h4>
            <form name="form1" method="POST" action="modificarcredenciales.php">
            <table border="0">
                <tbody>
                    <?php 

                    $consulta = "SELECT * FROM usuario_admin where id_admin=". $_SESSION['id_admin']."";
                    $resultado = mysql_query($consulta, $enlace);

                        while ($row = mysql_fetch_array($resultado)) {
                            $id = $row['id_admin'];
                            $_SESSION['usuario'] = $row['usuario'];
                            $password = $row['password'];
                        }               
                    ?>
                    <tr><input type="hidden" name="id" value="<?php echo $_SESSION['id_admin']?>"/>
                        <td>Usuario:</td>
                        <td><input type="text" name="usuario" required="" value="<?php echo $_SESSION['usuario']?>"</td>
                    </tr>
                    <tr>
                        <td>Password nueva:</td>
                        <td><input type="password" name="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" onchange="form.pwd2.pattern = this.value;" value="" /></td>
                    </tr>
                    <tr>
                        <td>Confirmar Password:</td>
                        <td><input type="password" name="pwd2" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}" title="Debe coincidir con el campo anterior" value=""/></td>
                    </tr>
                </tbody>
            </table>
                <input type="submit" name="guardar" value="Guardar" class="btn btn-success">
            </form>
                <?php
                    if (isset($_POST['guardar'])) {
                    $guardar = $_POST['guardar'];

                    if ($guardar == "Guardar"){
                        
                        $id = $_POST['id'];
                        $usuario = $_POST['usuario'];
                        $password = md5($_POST['password']);


                    $modificar = "UPDATE usuario_admin SET usuario='$usuario', password='$password'"
                                       . "WHERE id_admin = $id";

                    $query = mysql_query($modificar, $enlace);
                    if (!$query) {
                        echo 'No se modifico'.mysql_error();
                    }  else {   
                         echo "<script>alert('Credencial modificada');window.location.href=\"../../../logout.php\"</script>";
                    }       
                }
              }            
            ?>
          </div>
        </div><!--/span-->
      </div><!--/row-->
      <hr>
      <footer>
        <center><p>&copy; Conexi&oacute;n 2013</p></center>
      </footer>

    </div><!--/.fluid-container-->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/bootstrap-dropdown.js"></script>
  </body>
</html>
